﻿def CheckValidityWarhammer40k():
	List.ErrorMessage = ""
	list_total = List.Total
	entries = List.GetEntries()
	troops_count = int(entries.GetEntriesByCategory("3.Troop").Count)
	hq_count = int(entries.GetEntriesByCategory("1.HQ").Count)
	if hq_count < 1:
		List.ErrorMessage = "Not Enough HQ Choices, Min. of 1"
		return False
	if troops_count < 2:
		List.ErrorMessage = "Not Enough Troops Choices, Min. of 2"
		return False
	return True

def Requires(equipment):
	e = List.SelectedEntry
	u = e.Units[0]
	if u.IsItemEquipped(equipment):
		return True
	MessageBox.Show(equipment + " is required to equip this item", "Message")
	return False

def Generic_CheckMaximums(max, wargearName, replacementName):
	entry = List.SelectedEntry
	numberReplaced = 0
	for unit in entry.Units:
		if not unit.Equipment[wargearName]:
			continue
		if unit.Equipment[wargearName].IsReplaced:
			numberReplaced += 1
	if numberReplaced >= max:
	   for unit in entry.Units:
	   		if not unit.Equipment[wargearName]:
				continue
			if unit.Equipment[wargearName].IsReplaced and (max == 1 or unit.Equipment[wargearName].Replacement.Equipment.Name != replacementName):
				unit.Equipment[wargearName].Reset()
				numberReplaced -= 1
				if numberReplaced < max:
					break
	return True

def Generic_ToggledUpgrades(upgradeName):
	entry = List.SelectedEntry
	for upgrade in entry.Upgrades:
		if upgrade.Name == upgradeName:
			upgrade.Applied = True
		else:
			upgrade.Applied = False
	return False